package gui;

import gui.util.GUIUtils;
import gui.util.Relatorio;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.jgoodies.forms.layout.CellConstraints;

public class RelatorioGUI extends JDialog {
	private static final long serialVersionUID = 1L;
	
	private JPanel panelCentral;
	private JPanel panelRodape;
	private JComboBox comboTipoRelatorio;
	private JButton botaoImprimir;
	private JButton botaoCancelar;

	public RelatorioGUI() {
		//this.setModal(true);
		this.setTitle("Relat�rios");
//		this.setSize(400, 150);
//		this.setLayout(new BorderLayout());
		this.add(getPanelCentral(), BorderLayout.CENTER);
		this.add(getPanelRodape(), BorderLayout.SOUTH);

		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setResizable(false);
		pack();
		centralizar();
		this.setVisible(true);


	}

	public void centralizar() {
		Dimension so = Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation( 
				(( so.width-this.getSize().width ) / 2) , 
				(( so.height-this.getSize().height ) / 2 ) );  
	}


	public JPanel getPanelCentral() {
		if (panelCentral == null){
			panelCentral = new JPanel(GUIUtils.getLayout(3, 20));
			CellConstraints  cc = new CellConstraints();

			panelCentral.add(new JLabel("Tipo Relat�rio"),	cc.xywh(  2, 4,  7, 1, CellConstraints.RIGHT, CellConstraints.DEFAULT ));
			panelCentral.add(getComboTipoRelatorio(),		cc.xywh( 10, 4, 20, 1, CellConstraints.FILL, CellConstraints.DEFAULT ));
		}
		return panelCentral;
	}

	public JPanel getPanelRodape() {
		if (panelRodape == null){
			panelRodape = new JPanel();
			panelRodape.add(getBotaoImprimir());
			panelRodape.add(getBotaoCancelar());
		}
		return panelRodape;
	}

	public JComboBox getComboTipoRelatorio() {
		if (comboTipoRelatorio == null){
			comboTipoRelatorio = new JComboBox();
			comboTipoRelatorio.addItem("Usu�rios bloqueados");
			comboTipoRelatorio.addItem("Utiliza��o dos computadores por m�s");
			comboTipoRelatorio.addItem("Softwares por computador");
			comboTipoRelatorio.addItem("Hardwares por computador");
		}
		return comboTipoRelatorio;
	}


	public JButton getBotaoImprimir() {
		if (botaoImprimir == null){
			botaoImprimir = new JButton("Imprimir");
			botaoImprimir.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {

					String nomeReport = "relatorios/";
					
					if (getComboTipoRelatorio().getSelectedIndex() == 0){
						nomeReport += "UsuariosBloqueados";
					} else if (getComboTipoRelatorio().getSelectedIndex() == 1){
						nomeReport += "UtilizacaoComputadoresMes";
					} else if (getComboTipoRelatorio().getSelectedIndex() == 2){

					} else if (getComboTipoRelatorio().getSelectedIndex() == 3){

					}
					Relatorio viewer = new Relatorio(nomeReport + ".jasper");
					viewer.setVisible(true);

					viewer.setAlwaysOnTop(true);
					dispose();
				}
			});
		}
		return botaoImprimir;
	}
	public JButton getBotaoCancelar() {
		if (botaoCancelar == null){
			botaoCancelar = new JButton("Cancelar");
			botaoCancelar.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					dispose();
				}
			});
		}
		return botaoCancelar;
	}

	public static void main(String[] args) {
		new RelatorioGUI();
	}
}
